package crmdna.client.program;

import com.googlecode.objectify.Ref;
import com.googlecode.objectify.annotation.Cache;
import com.googlecode.objectify.annotation.Entity;
import com.googlecode.objectify.annotation.Id;
import com.googlecode.objectify.annotation.Index;
import com.googlecode.objectify.annotation.Load;

import crmdna.client.group.GroupEntity;
import crmdna.client.program.Program.ProgramProp;
import crmdna.client.programtype.ProgramTypeEntity;
import crmdna.client.teacher.TeacherEntity;
import crmdna.client.venue.VenueEntity;
import crmdna.common.Utils;

@Entity @Cache
public class ProgramEntity {
	@Id long programId;
	
	@Load @Index Ref<ProgramTypeEntity> programTypeRef;
	
	@Index int startYYYYMMDD;
	@Index int endYYYYMMDD;
	
	@Load @Index Ref<VenueEntity> venueRef;
	@Load @Index Ref<TeacherEntity> teacherRef;
	@Load @Index Ref<GroupEntity> groupRef;
	
	String description; //free text	
	int numBatches;	
	
	public ProgramProp toProp() {
		ProgramProp programProp = new ProgramProp();
		programProp.programId = programId;
		programProp.programTypeProp = programTypeRef.get().toProp();
		programProp.groupProp = groupRef.get().toProp();		
		programProp.startYYYYMMDD = startYYYYMMDD;
		programProp.endYYYYMMDD = endYYYYMMDD;
		programProp.venueProp = venueRef.get().toProp();
		programProp.teacherProp = teacherRef.get().toProp();
		programProp.description = description;
		programProp.numBatches = numBatches;
		
		programProp.name = programProp.programTypeProp.displayName + " " 
				+ Utils.getDurationAsString(startYYYYMMDD, endYYYYMMDD)  + " @ "				
				+ venueRef.get().toProp().displayName 
				+ " (" + groupRef.get().toProp().displayName + ")"; 
		//eg: IshaKriya 3 Feb 2014 @ Woodlands CC (Singapore)
									
		return programProp;
	}
}
